/* $Header: gc_cmds.c,v 2.2 01/10/02 10:29:16 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: gc_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*          Lesley Freed                                               */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the general commands which  */
/*            which effect the overall gc.                             */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <config.h>
#include <zone_status.h>
#include <status.h>

#include <error.h>

#include <clock_ui.h>
#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <method.h>
#include <hostutil.h>

#include <display_ui.h>
#include <cmd_tbls.h>
#include <kbd_ui.h>
#include <run_ui.h>
#include <readiness.h>
#include <iomap.h>
#include <leds.h>
#include <exception.h>
#include <glp.h>
#include <sequence.h>
#include <seq_ui.h>
#include <sampler.h>
#include <i_op.h>
#include <recovery_ui.h>

#include <timetable.h>
#include <zone_ui.h>
#include <p_status.h>
#include <det_ui.h>

#include <flash.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/

/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/

/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

extern CMD_QUEUE_TYPE  Free_Cmd_Q;
extern CMD_QUEUE_TYPE  GC_Cmd_Q;
extern QUEUE_TYPE   Wr_Free_Q;
extern BIT8   GetDetHostModel ( POSITION position  );
extern U_INT16         HSS_HX_cccc[];

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/



/*****************************/
/*   MACROS                  */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/



/***********************************************************************/
/* FUNCTION: DoGCEO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Echo command.                                              */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoGCEO(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
U_INT16 len;

   len = 0;

   if (p_cmd->parmv[0] == 1)
   {
      len = PutAsciiParam((BIT8 *)"\"", p_resp_parm);
      len += PutAsciiParam((BIT8 *)&(p_cmd->parms[p_cmd->parmv[1]]),
                                     p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)"\"", p_resp_parm+len);
      return len;
   }
   else
   {
      CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoGCEO                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCDL                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Set display pointer to the keyboard display buffer so the  */
/*              contents of the keyboard display buffer is displayed.  */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCDL(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   (void)p_resp_parm;
   (void)p_cmd;

   RestoreDisplay();

   return  NO_RESPONSE;
}

/***********************************************************************/
/* END FUNCTION: DoGCDL                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCDH                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Clears the host display buffer and set display pointer     */
/*           to display the host display buffer.                       */
/*                                                                     */
/* RETURNED VALUE: no response to the command - returns zero           */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCDH(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{

   (void)p_resp_parm;
   (void)p_cmd;

   ClearDisplay();

   return  NO_RESPONSE;
}

/***********************************************************************/
/* END FUNCTION: DoGCDH                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCDR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Controls the REMOTE LED on the front panel of IQ.          */
/*                                                                     */
/* RETURNED VALUE: no response to command - returns zero               */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCDR(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{

   (void)p_resp_parm;
   (void)p_cmd;

   /* Check to see if there is a parameter */
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   else
   {
      switch( p_cmd->parms[p_cmd->parmv[1]] )
      {
      case  '0':
 //        TURN_REMOTE_LED_OFF();
         break;
      case  '1':
 //        TURN_REMOTE_LED_ON();
         break;
      case  '2':
 //        BLINK_REMOTE_LED();
         break;
      default:
         CmdErrorHandler( p_cmd, 1, INVALID_PARAM );
         break;
      }
   }

   return  NO_RESPONSE;
}

/***********************************************************************/
/* END FUNCTION: DoGCDR                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCDI                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Returns the state of the front panel LED indicators.       */
/*          0 = off, 1 = on, 2 = blinking.                             */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCDI(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
  INT16  length;
  (void)p_cmd;
  mLog("DoGCDI..\n");

   /*
   length = PutIntParam( GET_NOT_READY_LED(), p_resp_parm, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_PREP_RUN_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_RUN_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_POST_RUN_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_INIT_TIME_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_RAMP_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_FINAL_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_FRONT_MISER_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_BACK_MISER_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_REMOTE_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_CLOCK_TBL_LED(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   length += PutIntParam( GET_DEVIATION_LED(), p_resp_parm+length, 0 );
   */
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCDI                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCKB                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Returns contents of the keyboard buffer.                   */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCKB(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
INT16   parm_len;

   (void)p_cmd;
   mLog("DoGCKB\n");
   /*
   parm_len = GetKeyHistory( (BIT8 *)p_resp_parm );
   */
   return  parm_len;
}

/***********************************************************************/
/* END FUNCTION: DoGCKB                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCKP                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Executes the keycode sequence recieved.                    */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCKP(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   U_INT16 i;

   mLog("DoGCKP\n");
/*
   for ( i = 1; i <= p_cmd->parmv[0]; i++ )
   {
      //Execute the individual key codes 
      SetDataCommKeycode( p_cmd->parms[p_cmd->parmv[i]] );

   }

   parm_len =  PutIntParam( (INT32)OK, p_resp_parm, 0 );
   */
   return parm_len;
}

/***********************************************************************/
/* END FUNCTION: DoGCKP                                                */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: DoGCDX                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: This command will read or write to the display.            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/* NOTE:  The sent and returned display strings are assumed to be      */
/*        "wrapped" in quote marks.  For example:                      */
/*                                                                     */
/*        " Initial temp     50"                                       */
/*                                                                     */
/***********************************************************************/


INT16 DoGCDX(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   U_INT8  line_no;
   INT16   str_len;

   parm_len =  NO_RESPONSE;

   /* Check to see if there is a parameter */
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
      return NO_RESPONSE;
   }

   line_no = p_cmd->opcode.char_op[1] - '0';

   if ( p_cmd->parms[p_cmd->parmv[1]] == '?' )
   {
      /* Read the contents of a display line */
      parm_len = PutAsciiParam((BIT8 *)"\"",p_resp_parm);
      parm_len += GetDisplayLine( ( BIT8 *)(p_resp_parm+parm_len), line_no );
      parm_len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+parm_len);

   }
   else
   {
      /* Write to a display line */

      str_len = StrLen( &p_cmd->parms[p_cmd->parmv[1]] );

      /* Check to see if the string is at least 2 characters long and that */
      /* the first and last character are quotes.                          */
      if ( ( str_len >= 2 ) &&
           ( p_cmd->parms[p_cmd->parmv[1]] == '\"' ) &&
           ( p_cmd->parms[p_cmd->parmv[1]+str_len-1] == '\"' ) )
      {
         /* First put a NULL BIT8 at the end of the string where the       */
         /* trailing quote BIT8 is found.                                  */
         p_cmd->parms[ p_cmd->parmv[1]+str_len-1 ] = 0;

         SetDisplayLine( (BIT8 *)&p_cmd->parms[p_cmd->parmv[1]+1], line_no );
      }
      else
      {
         CmdErrorHandler( p_cmd, 1, SYNTAX_ERROR );
      }

   }

   return  parm_len;
}

/***********************************************************************/
/* END FUNCTION: DoGCDX                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCBX                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: This command will read or write to a mailbox.              */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCBX(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16   parm_len;
   U_INT8  mailbox_no;
   INT16   str_len;
   mLog("DoGCBX\n");
   /*
   parm_len =  NO_RESPONSE;

   // Check to see if there is a parameter 
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
      return NO_RESPONSE;
   }

   // find mailbox number 
   mailbox_no = p_cmd->opcode.char_op[1] - '0';

   if ( p_cmd->parms[p_cmd->parmv[1]] == '?' )
   {
      parm_len = 0;

      // read mailbox 
      StrNCpy(p_resp_parm,Mailbox[mailbox_no].time,6);
      parm_len += 6;
      parm_len += PutAsciiParam((BIT8 *)",",p_resp_parm+parm_len);
      StrNCpy(p_resp_parm+parm_len,Mailbox[mailbox_no].date,6);
      parm_len += 6;
      parm_len += PutAsciiParam((BIT8 *)",",p_resp_parm+parm_len);
      parm_len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+parm_len);
      StrNCpy(p_resp_parm+parm_len, Mailbox[mailbox_no].message,
                                    Mailbox[mailbox_no].msg_len);
      parm_len = parm_len + Mailbox[mailbox_no].msg_len;
      parm_len += PutAsciiParam((BIT8 *)"\"",p_resp_parm+parm_len);
   }
   else
   {
      // Write to mailbox 

      str_len = StrLen( &p_cmd->parms[p_cmd->parmv[1]] );

      // Check to see if the string is to big for mailbox 
      //    if so, truncate 
      if (str_len > MAILBOX_SIZE)
      {
         str_len = MAILBOX_SIZE;
      }

      INTERRUPTS_OFF;
      StrNCpy(Mailbox[mailbox_no].message,
                         (BIT8 *)&p_cmd->parms[p_cmd->parmv[1]], str_len );
      Mailbox[mailbox_no].msg_len = str_len;

      (void)IntToDecFilled( GetFullClockTime(),Mailbox[mailbox_no].time,6 );
      (void)IntToDecFilled( GetFullDate(),Mailbox[mailbox_no].date,6 );
      INTERRUPTS_ON;

   }
   */
   return  parm_len;

}

/***********************************************************************/
/* END FUNCTION: DoGCBX                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCSP                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Executes the stop command, which acts like a pressing      */
/*              the STOP key on the keyboard.                          */
/*                                                                     */
/* RETURNED VALUE: always return 0 indicating command executed.        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCSP(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   (void)p_cmd;

   /* issue stop command as it would have come from the keyboard */
   StopRun( Abort );

   return   PutIntParam( (INT32)OK, p_resp_parm, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoGCSP                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCPR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Executes the go to pre run command, which behaves          */
/*          identical to pressing the PREP RUN key on the keyboard.    */
/*                                                                     */
/*                                                                     */
/* RETURNED VALUE: always return 0 indicating command executed.        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCPR(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   (void)p_cmd;

   INTERRUPTS_OFF;
   /* Low level start request function */
   if ( (Run_State == RUN_IDLE) || (Run_State == POST_RUN) )
   {
      Prepare(Auto);
      INTERRUPTS_ON;
      return   PutIntParam( (INT32)OK, p_resp_parm, 0 );
   }
   else
   {
      INTERRUPTS_ON;
      return   PutIntParam( (INT32)NOT_ALLOWED, p_resp_parm, 0 );
   }
}

/***********************************************************************/
/* END FUNCTION: DoGCPR                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCSR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Executes the start request command, which will activate    */
/*              the start request line on the APG Remote connector.    */
/*              No checking is done.                                   */
/*                                                                     */
/* RETURNED VALUE: always return 0 indicating command executed.        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 DoGCSR(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   (void)p_cmd;

   /* Low level start request function */
   AssertApgStartRequest();

   return   PutIntParam( (INT32)OK, p_resp_parm, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoGCSR                                                */
/***********************************************************************/




/***********************************************************************/
/* FUNCTION: DoGCCF                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Routine to handle the report configuration command.        */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

const BIT8 CF_FORMAT[] =
{
   1,    /* OVEN */
   0,
   0,
   2,    /* FRONT DETECTOR */
   0,
   0,
   0,
   0,
   0,
   3,    /* BACK DETECTOR */
   0,
   0,
   0,
   0,
   0,
   4,    /* FRONT INLET */
   0,
   0,
   0,
   5,    /* BACK INLET */
   0,
   0,
   0,
   6,    /* AUX 1 */
   0,
   7,    /* AUX 2 */
   0,
   8,    /* AUX 3 */
   0,
   9,    /* AUX 4 */
   0,
  10,    /* AUX 5 */
   0,
  11,    /* VALVE 1 */
  12,    /* VALVE 2 */
  13,    /* VALVE 3 */
  14,    /* VALVE 4 */
  15,    /* VALVE 5 */
  16,    /* VALVE 6 */
  17,    /* VALVE 7 */
  18,    /* VALVE 8 */
  19,    /* MIO BD  */
  20,    /* SAMPLER SYSTEM  */
   0,
   0,
   0,
   0,
  21,    /* EPC BOARD PRESENCE */
};

#define MAX_CONFIG_TYPE 21

INT16 DoGCCF(CMD_TYPE *p_cmd, BIT8 *p_resp_parm, const METHCMD  *p_cmd_table)
{

   U_INT16  length;
   U_INT16  i;
   INT32    param_index;
   UI_ERR   error;
   INT32    config_type;

   error = OK;
   length = 0;

   if ( p_cmd->parmv[0] < 1 )
   {
       /* missing parameters */
       CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
       return PutIntParam( (INT32)MISSING_PARAM, p_resp_parm, 0 );
   }

   /* check if host wants to read setpoints */
   if ( p_cmd->parms[0] == '?' )
   /* read setpoints */
   {
      length = 0;

      for( param_index = 0 ; error == OK ; param_index++)
      {
         /* add ',' if not first parameter or end of line */
         if( param_index != 0 )
         {
            if ( CF_FORMAT[param_index] == 0 )
            {
               length += PutAsciiParam((BIT8 *)"," , p_resp_parm+length);
            }
            else
            {
               length += PutAsciiParam((BIT8 *)"\\n" , p_resp_parm+length);
            }
         }

         error = GetWkfileParam( p_resp_parm+length, p_cmd_table, param_index );
         if ( error == OK )
         {
            /* add length of new parameter */
            length += StrLen(p_resp_parm+length);
         }
         else
         {
            /* remove ',' or "//n" if added */
            if( param_index != 0 )
            {
               length--;
               if ( CF_FORMAT[param_index] != 0 )
               {
                  length--;
               }
            }
         }
      }
   }
   else
   {
      /* See which configuration to report */
      /* REVISIT: check for error returned from DecToInt  */
      (void)DecToInt( &p_cmd->parms[p_cmd->parmv[1]],0, &config_type  );

      if ( ( config_type > 0 ) && ( config_type <= MAX_CONFIG_TYPE ) )
      {
         /* First find the get configuration functions to use */
         i = 0;
         while ((CF_FORMAT[i] != config_type) && (i< MAXINDEX(CF_FORMAT,BIT8)))
         {
            i++;
         }

         do
         {
            error = GetWkfileParam(p_resp_parm+length,p_cmd_table, i);

            /* add length of new parameter */
            length += StrLen(p_resp_parm+length);

            i++;

            /* See if there is another parameter */
            if ( CF_FORMAT[i] == 0 )
            {
               length += PutAsciiParam((BIT8 *)"," , p_resp_parm+length);
            }
         }
         while ((CF_FORMAT[i] == 0) && (i < MAXINDEX(CF_FORMAT,BIT8)));
      }
      else
      {
         CmdErrorHandler( p_cmd, 1, INVALID_PARAM );
         length = PutIntParam( (INT32)INVALID_PARAM, p_resp_parm, 0 );
      }
   }

   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCCF                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCIN                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Sets "Controlled_By_Host" mode ON/OFF                      */
/*                  0 -> OFF                                           */
/*                  1 -> ON                                            */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/* WARNINGS: always returns "OK" to sender, even if the command fails  */
/*           due to invalid parameters.                                */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCIN(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 value;
   UI_ERR ui_err;

   /* check to see if there is a parameter */
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   /* check that parameter is numeric */
   else if ( (ui_err = DecToInt(&p_cmd->parms[p_cmd->parmv[1]], 0, &value)) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }
   /* attempt to store param value */
   else if ( (ui_err = SetControlledByHost( value )) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }

   /* return something so sender knows mode change is complete */
   return PutIntParam( (INT32)OK, p_resp_parm, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoGCIN                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCRL                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Return an entry from the IQ Run Log.                       */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/***********************************************************************/

static  INT16 DoGCRL(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 log_index, dev_code, length;
   UI_ERR ui_err;
   BIT8 string[61];  /* overkill:  enough space for 20 alternating chars */

   length = NO_RESPONSE;

   /* check to see if there is a parameter */
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   /* check that parameter is numeric */
   else if ( (ui_err = DecToInt(&p_cmd->parms[p_cmd->parmv[1]], 0, &log_index)) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }
   /* check that parameter is >= 1 */
   else if (log_index < 1)
   {
      CmdErrorHandler( p_cmd, 1, INVALID_PARAM );
   }
   /* check if GLP log entry exists */
   else if ( DEVIATIONS_FOUND && ((dev_code = GetGlpEntryLine(log_index-1, 1, string)) != -1 ) )
   {
      /* format response string */
      length = PutIntParam( dev_code, p_resp_parm, 0 );
      length += PutAsciiParam( (BIT8 *)",\"", p_resp_parm+length );
      length += PutAsciiParam( string, p_resp_parm+length );

      (void)GetGlpEntryLine(log_index-1, 2, string);
      length += PutAsciiParam( (BIT8 *)"\",\"", p_resp_parm+length );
      length += PutAsciiParam( string, p_resp_parm+length );

      (void)GetGlpEntryLine(log_index-1, 3, string);
      length += PutAsciiParam( (BIT8 *)"\",\"", p_resp_parm+length );
      length += PutAsciiParam( string, p_resp_parm+length );
      length += PutAsciiParam( (BIT8 *)"\"", p_resp_parm+length );
   }
   else
   {
      /* entry does not exist */
      length = PutAsciiParam( (BIT8 *)"0,\"\",\"\",\"\"", p_resp_parm );
   }

   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCRL                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCRN                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Changes GC run state in Controlled_By_Host operation.      */
/*             0 -> RUN IDLE                                           */
/*             1 -> PRE RUN                                            */
/*             2 -> RUN                                                */
/*             3 -> POST RUN                                           */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/* WARNINGS: always returns "OK" to sender, even if the command fails  */
/*           due to invalid parameters.                                */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRN(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 value, abort = FALSE;
   UI_ERR ui_err;

   /* check to see if there is at least 1 parameter */
   if ( p_cmd->parmv[0] < 1 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   /* check that parameter is numeric */
   else if ( (ui_err = DecToInt(&p_cmd->parms[p_cmd->parmv[1]], 0, &value)) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }
   /* if an "abort" value is specified try to read it; default to FALSE if it is not specified */
   else if ( (p_cmd->parmv[0] > 1) && ((ui_err = DecToInt(&p_cmd->parms[p_cmd->parmv[2]], 0, &abort)) != OK) )
   {
      CmdErrorHandler( p_cmd, 2, ui_err );
   }
   /* attempt to change run state */
   else if ( (ui_err = SetRunState( value, abort )) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }
   /* return something so sender knows mode change is complete */
   return PutIntParam( (INT32)OK, p_resp_parm, 0 );
}

/***********************************************************************/
/* END FUNCTION: DoGCRN                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCHR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Sets and returns host readiness.                           */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCHR(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 length;
   INT32 param;

   (void) p_cmd;

   length = NO_RESPONSE;

   if ( p_cmd->parmv[0] < 1 )
   {
       /* missing parameters */
       CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   /* check if host wants to read setpoints */
   else if ( p_cmd->parms[0] == '?' )
   {

      /* return host (datacomm) readiness */
      length = PutIntParam( (HostReady()) ? 1 : 0, p_resp_parm, 0 );

   }
   /* try to read integer parameter */
   else if (DecToInt(&p_cmd->parms[0], 0, &param) == OK)
   {
      if (param == 0)
      {
         SetHostReady(FALSE);
      }
      else if (param == 1)
      {
         SetHostReady(TRUE);
      }
      else
      {
         CmdErrorHandler( p_cmd, 1, INVALID_PARAM);
      }
   }
   else
   {
      CmdErrorHandler( p_cmd, 1, INVALID_PARAM);
   }
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCHR                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCRY                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Returns summary of GC readiness status.                    */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRY(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 length;

   (void) p_cmd;
   mLog("DoGCRY\n");
   /*
   // return external (APG) readiness 
   length = PutIntParam( (ExternalReady()) ? 1 : 0, p_resp_parm, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   // return internal (GC) readiness 
   length += PutIntParam( (INT32)InternalReadyEval(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   // return host (datacomm) readiness 
   length += PutIntParam( (HostReady()) ? 1 : 0, p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   // return internal ready for pre run 
   length += PutIntParam((INT32)InternalReadyForPrepRunEval(),
                       p_resp_parm+length,0);
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   // return powerfail recovery status 
   length += PutIntParam( (INT32)GetPowerFailRecovery(), p_resp_parm+length, 0 );
   length += PutAsciiParam( (BIT8 *)"," , p_resp_parm+length );

   // return powerfail blank run state 
   length += PutIntParam( Power_Fail_Blank_Run ? 1 : 0, p_resp_parm+length, 0 );
   */
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCRY                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCSI                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Return sample information from the last injection.         */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCSI(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16 length;

   (void)p_cmd;
   mLog("DoGCSI\n");
   /*
   // front sample # 
   length = PutIntParam( GetFrontSample(), p_resp_parm, 0 );

   /* front barcode, surrounded by quotes. 
   length += PutAsciiParam( (BIT8 *)",\"", p_resp_parm+length );
   length += PutAsciiParam( TowerF.barcode, p_resp_parm+length );

   /* back sample # (and front barcode closing quote) 
   length += PutAsciiParam( (BIT8 *)"\",", p_resp_parm+length );
   length += PutIntParam( GetBackSample(), p_resp_parm+length, 0 );

   /* back barcode, surrounded by quotes. 
   length += PutAsciiParam( (BIT8 *)",\"", p_resp_parm+length );
   length += PutAsciiParam( TowerB.barcode, p_resp_parm+length );
   length += PutAsciiParam( (BIT8 *)"\"", p_resp_parm+length );
   */
   return length;
}

/***********************************************************************/
/* FUNCTION: DoGCSQ                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Control IQ sequence engine via datacomm.                   */
/*             0 -> reset                                              */
/*             1 -> do next sequence step                              */
/*             2 -> halt sequence and backup one step                  */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*             action 0 returns <OK>                                   */
/*             action 1 returns <OK>|<NOT_ALLOWED>                     */
/*                                                                     */
/* WARNINGS: should always be invoked with "0" before commencing a new */
/*           sequence.                                                 */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCSQ(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 value;
   INT16 length ;
   UI_ERR ui_err;
   mLog("DoGCSQ\n");
   /*
   length = NO_RESPONSE;

   /* check to see if there is a parameter 
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   /* check that parameter is numeric 
   else if ( (ui_err = DecToInt(&p_cmd->parms[p_cmd->parmv[1]], 0, &value)) != OK )
   {
      CmdErrorHandler( p_cmd, 1, ui_err );
   }
   /* reset? 
   else if (value == 0)
   {
      ResetSequence();
      length = PutIntParam( (INT32)OK, p_resp_parm, 0 );  /* always OK 
   }
   /* do next sequence step? 
   else if (value == 1)
   {
      ui_err = StepSequence();
      length = PutIntParam( (INT32)ui_err, p_resp_parm, 0 );
   }
   /* halt and backup? 
   else if (value == 2)
   {
      HaltAndBackupSequence();
      length = PutIntParam( (INT32)OK, p_resp_parm, 0 );  /* always OK 
   }
   /* invalid param value 
   else
   {
      CmdErrorHandler( p_cmd, 1, INVALID_PARAM );
   }
   */
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCSQ                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCSS                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Get the status of a sequence.                              */
/*                                                                     */
/* RETURNED VALUE: number of chars written to *p_resp_parm             */
/*             returns <OK>|<NOT_ALLOWED>|<NOT_VALID_DURING_RUN        */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCSS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   UI_ERR ui_err;
   INT16 length;
   mLog("DoGCSS\n");
   /*
   (void) p_cmd;        /* unused param 
   ui_err = GetSeqStatus();
   length = PutIntParam( (INT32)ui_err, p_resp_parm, 0 );
   */
   return length;
}

/***********************************************************************/
/* END FUNCTION: DoGCSS                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCRD                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Clear/Delete the runtime table                             */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  DeleteTimeTableEntry                                        */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRD(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 entry;
   UI_ERR err;

   mLog("DoGCRD\n");
   /*
   if( (p_cmd->parmv[0] == 1) && (p_cmd->parms[p_cmd->parmv[1]] == '?') )
   {
      /* Only used for creating workfile
       *    this will put GCGCRD 0 in workfile which will delete
       *    run table during download.
       
      return  PutAsciiParam( (BIT8 *)"0", p_resp_parm);
   }
   else if(p_cmd->parmv[0] == 1)
   {
      err = DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &entry );
      if ( (err != OK) || (entry > 25) )
      {
         CmdErrorHandler( p_cmd, 1, err );
         return NO_RESPONSE;
      }
      if (entry == 0)
      {
         /* Delete the entire run table 
         DeleteEntireTimeTable();
         return NO_RESPONSE;
      }
      err = DeleteTimeTableEntry(entry);
      if (err != OK)
      {
         CmdErrorHandler( p_cmd, 1, err );
      }
      return NO_RESPONSE;
   }
   else
   {
      /* Delete the entire run table 
      DeleteEntireTimeTable();
      return NO_RESPONSE;
   }
   */
}

/***********************************************************************/
/* END FUNCTION: DoGCRD                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCRR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Report the entire runtime table contents                   */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  GetTimeTableEntry                                           */
/*                                                                     */
/* LIMITATIONS:  Returns 0,0,0 for an unused entry number.             */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRR( BIT8 *p_resp_parm )
{
   INT16    len;
   U_INT8   type;
   INT32    time, parm, entry_num;
   mLog("DoGCRR\n");
   /*
   len = 0;

   for ( entry_num = 1; entry_num < NUM_TIME_TABLE_ENTRIES; entry_num++ )
   {
      /* Get the entry and report zeros if no entry 
      if ( GetTimeTableEntry( entry_num, &time, &type, &parm ) != OK )
      {
         time = type = parm = 0;
      }
      else
      {
         /* Convert the timetable entry setpoint back to data comm units 
         parm = GetDcRunTableParm( (RTT_EVENT)type, parm );
      }

      len += PutIntParam( time, p_resp_parm+len, 2 );
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
      len += PutIntParam( type, p_resp_parm+len, 0 );
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
      len += PutIntParam( parm, p_resp_parm+len, 0 );
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
   }
   len--;                                /* remove the comma 
   */
   return len;
}

/***********************************************************************/
/* END FUNCTION: DoGCRR                                                */
/***********************************************************************/


static U_INT8 OEMSkipCheck(RTT_EVENT  type  )
{
  mLog("OEMSkipCheck\n");
  /*
     if ( GetLSMSeqLock() == 0 ) return 0 ;

     switch (type )
     {
        case FRONT_OIM1:
        case FRONT_OIM2:
        case FRONT_OIM3:
        case FRONT_OIM4:
        case FRONT_OEM5:
        case FRONT_OEM7:
           if (
                ( GetDetHostModel(FRONT) != TYPE_13_14_AS_IS )
                &&
                ( (GetDetectorType(FRONT) == OEM_AIB) || (GetDetectorType(FRONT) == OEM_FID) )
              ) return 1 ;
           break ;

        case  BACK_OIM1:
        case  BACK_OIM2:
        case  BACK_OIM3:
        case  BACK_OIM4:
        case  BACK_OEM5:
        case  BACK_OEM7:
           if (
                ( GetDetHostModel(BACK) != TYPE_13_14_AS_IS )
                &&
                ( (GetDetectorType(BACK) == OEM_AIB) || (GetDetectorType(BACK) == OEM_FID) )
              ) return 1 ;
           break ;
     };
     */
     return 0 ;

}

/***********************************************************************/
/* FUNCTION: DoGCRT                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Set a runtime table entry                                  */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  AddTimeTableEntry                                           */
/*                                                                     */
/* LIMITATIONS:  You cannot specify which entry number, it will go in  */
/*               the table in the entry number determined by it's      */
/*               time setpt.  It will be placed after any entries with */
/*               the same time setpt.                                  */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRT(CMD_TYPE *p_cmd )
{
   UI_ERR   error;
   U_INT8   entry_num;
   INT16    len;
   INT32    type, time, parm;
   mLog("DoGCRT\n");

   len = NO_RESPONSE;

   /*************************/
   /* Add a run table entry */
   /*************************/
   /*

   /* Check to see if there's a fundamental problem with the parameters 
   /* making it impossible to convert one or more of them.              
   if ( DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 2, &time ) ||
        DecToInt( &p_cmd->parms[p_cmd->parmv[2]], 0, &type ) ||
        DecToInt( &p_cmd->parms[p_cmd->parmv[3]], 0, &parm ) )
   {
      CmdErrorHandler( p_cmd, 0, SYNTAX_ERROR );
      return len;
   }

   /* if type == NULL_EVENT, then no entry (do nothing) 
   if ( type == (INT32)NULL_EVENT )
   {
      return len;
   }

   /* Check each of the parameters for consistency.  If any one of them 
   /* is unacceptable we will not add a run table entry.                
   if ( (error = CheckTimeSetpt( time )) != OK )
   {
      CmdErrorHandler( p_cmd, 1, error );
      return len;
   }

   if ( (error = CheckRunTableType( type )) != OK )
   {
      CmdErrorHandler( p_cmd, 2, error );
      return len;
   }

   if ( (error = CheckRunTableParam( (RTT_EVENT)type, parm )) != OK )
   {
      CmdErrorHandler( p_cmd, 3, error );
      return len;
   }

   /* The parameters are OK, so add an entry 
   if ( (error = AddTimeTableEntry(time, type,
                                   GetIuRunTableParm((RTT_EVENT)type,parm),
                                   &entry_num)) != OK)
   {
      (void) entry_num;
      /* The table may be full 
      CmdErrorHandler( p_cmd, 0, error );
   }
   */
   return len;
}

/***********************************************************************/
/* END FUNCTION: DoGCRT                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCRx                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Report or Set a runtime table entry. The entry number is   */
/*          specified in the opcode, e.g. GCssRa indicates the first   */
/*          entry, GCssRc the third entry.                             */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  AddTimeTableEntry or GetTimeTableEntry                      */
/*                                                                     */
/* LIMITATIONS:  Although you specify entry number for entry, it will  */
/*               go in the table in the entry number determined by it's*/
/*               time setpt.  It will be placed after any entries with */
/*               the same time setpt.                                  */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCRx(CMD_TYPE *p_cmd, BIT8 *p_resp_parm )
{
   INT16  len;
   U_INT8 type, entry_num;
   INT32  time, parm;
   UI_ERR error;
   mLog("DoGCRx\n");
   len = NO_RESPONSE;
   /*
   /* Check to see if there is a parameter 
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   else
   {
      /* Check if we should return the entry 
      if( p_cmd->parms[p_cmd->parmv[1]] == '?' )
      {
         /* Get the entry number 
         entry_num = p_cmd->opcode.char_op[1] - 'a' + 1;

         /* Get the entry 
         error = GetTimeTableEntry( entry_num, &time, &type, &parm );

         if ( error == TABLE_ENTRY_EMPTY )
         {
            time = type = parm = 0;
            error = OK;
         }
         else
         {
            /* Convert the timetable entry setpoint back to data comm units 
            parm = GetDcRunTableParm( (RTT_EVENT)type, parm );
         }

         if ( 1 == OEMSkipCheck((RTT_EVENT)type) ) return len;

         if ( error == OK )
         {
            len  = PutIntParam( time, p_resp_parm, 2 );
            len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
            len += PutIntParam( type, p_resp_parm+len, 0 );
            len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
            len += PutIntParam( parm, p_resp_parm+len, 0 );
         }
         else
         {
            CmdErrorHandler( p_cmd, 0, error );
         }
      }
      else
      {
         /* Write an entry 
         len = DoGCRT( p_cmd );
      }
   }
   */
   return len;
}

/****************************  CLOCK TABLE  ****************************/


/***********************************************************************/
/* FUNCTION: DoGCCD                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Clear/Delete the clock table                               */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:  DeleteClockTableEntry                                       */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCCD(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT32 entry;
   UI_ERR err;

   (void) p_resp_parm;
   mLog("DoGCCD\n");
   /*
   if(p_cmd->parmv[0] == 1)
   {
      err = DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &entry );
      if ( (err != OK) || (entry > 25) )
      {
         CmdErrorHandler( p_cmd, 1, err );
         return NO_RESPONSE;
      }
      if (entry == 0)
      {
         /* Delete the entire clock table 
         DeleteEntireClockTable();
         return NO_RESPONSE;
      }
      err = DeleteClockTableEntry(entry);
      if (err != OK)
      {
         CmdErrorHandler( p_cmd, 1, err );
      }
      return NO_RESPONSE;
   }
   else
   {
      /* Delete the entire clock table 
      DeleteEntireClockTable();
      return NO_RESPONSE;
   }
   */
}

/***********************************************************************/
/* END FUNCTION: DoGCCD                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCCR                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Report the entire clock table contents                     */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:  Returns 0,0,0 for an unused entry number.             */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCCR( BIT8 *p_resp_parm )
{
   INT16    len;
   U_INT8   type;
   INT32    time, parm, entry_num;
   mLog("DoGCCR\n");
   len = 0;
   /*
   for ( entry_num = 1; entry_num < NUM_TIME_TABLE_ENTRIES; entry_num++ )
   {
      /* Get the entry and report zeroes if no entry 
      if ( GetClockTableEntry( entry_num, &time, &type, &parm ) != OK )
      {
         time = type = parm = 0;
      }

      (void) IntToDecFilled( time, p_resp_parm+len, 4);
      len += 4;
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
      len += PutIntParam( type, p_resp_parm+len, 0 );
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
      len += PutIntParam( parm, p_resp_parm+len, 0 );
      len += PutAsciiParam( (BIT8 *)",", p_resp_parm + len );
   }
   len--;                                /* remove the comma 
   */
   return len;
}

/***********************************************************************/
/* END FUNCTION: DoGCCR                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: DoGCCT                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Set a clock table entry                                    */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:  You cannot specify which entry number, it will go in  */
/*               the table in the entry number determined by it's      */
/*               time setpt.  It will be placed after any entries with */
/*               the same time setpt.                                  */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCCT(CMD_TYPE *p_cmd )
{
   UI_ERR   error;
   U_INT8   entry_num;
   INT16    len;
   INT32    type, time, parm;

   len = NO_RESPONSE;
   mLog("DoGCCT\n");
   /*************************/
   /* Add a run table entry */
   /*************************/

   /*
   /* Check to see if there's a fundamental problem with the parameters 
   /* making it impossible to convert one or more of them.              
   if ( DecToInt( &p_cmd->parms[p_cmd->parmv[1]], 0, &time ) ||
        DecToInt( &p_cmd->parms[p_cmd->parmv[2]], 0, &type ) ||
        DecToInt( &p_cmd->parms[p_cmd->parmv[3]], 0, &parm ) )
   {
      CmdErrorHandler( p_cmd, 0, SYNTAX_ERROR );
      return len;
   }

   /* if type == NULL_EVENT, then no entry (do nothing) 
   if ( type == (INT32)NULL_EVENT )
   {
      return len;
   }

   /* Check each of the parameters for consistency.  If any one of them 
   /* is unacceptable we will not add a run table entry.                
   if ( (error = CheckClockTime( time )) != OK )
   {
      CmdErrorHandler( p_cmd, 1, error );
      return len;
   }

   if ( (error = CheckClockTableType( (CTT_EVENT)type )) != OK )
   {
      CmdErrorHandler( p_cmd, 2, error );
      return len;
   }

   if ( (error = CheckClockTableParam( (CTT_EVENT)type, parm )) != OK )
   {
      CmdErrorHandler( p_cmd, 3, error );
      return len;
   }

   /* The parameters are OK, so add an entry 
   if ( (error = AddClockTableEntry(time, type, parm, &entry_num)) != OK)
   {
      (void) entry_num;
      /* The table may be full 
      CmdErrorHandler( p_cmd, 0, error );
   }
   */
   return len;
}

/***********************************************************************/
/* END FUNCTION: DoGCCT                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: DoGCHS                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Access information about an arrached headspace sampler     */
/*                                                                     */
/* RETURNED VALUE: INT16 response length                               */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

static INT16 DoGCHS(CMD_TYPE *p_cmd, BIT8 *p_resp_parm)
{
   INT16    len;

   len = NO_RESPONSE;
   mLog("DoGCHS\n");
   /*
   /* Check to see if there is a parameter 
   if ( p_cmd->parmv[0] == 0 )
   {
      CmdErrorHandler( p_cmd, 1, MISSING_PARAM );
   }
   else
   {
      /* Check if we should return the entry 
      if( p_cmd->parms[p_cmd->parmv[1]] == '?' )
      {
         len  = IntToDec( HSS_HX_cccc[1], p_resp_parm     );
         len += PutAsciiParam((BIT8 *)"," , p_resp_parm+len);
         len += IntToDec( HSS_HX_cccc[2], p_resp_parm+len );
         len += PutAsciiParam((BIT8 *)"," , p_resp_parm+len);
         len += IntToDec( HSS_HX_cccc[3], p_resp_parm+len );
         len += PutAsciiParam((BIT8 *)"," , p_resp_parm+len);
         len += IntToDec( HSS_HX_cccc[4], p_resp_parm+len );
      }
      else
      {
         CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      }
   }
   */
   return len;
}

/***********************************************************************/
/* END FUNCTION: DoGCCT                                                */
/***********************************************************************/


/***********************************************************************/
/* FUNCTION: GCOpcodes                                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls routines to implement the GC commands.               */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

INT16 GCOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len)
{
INT16           parm_len;

   (void) max_resp_len;

   parm_len = NO_RESPONSE;
   switch( p_cmd->opcode.int_op )
   {
     /*
      case  MAKEINT('D','L'):
         parm_len = DoGCDL(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('D','H'):
         parm_len = DoGCDH(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('D','I'):
         parm_len = DoGCDI(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('D','R'):
         parm_len = DoGCDR(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('K','B'):
         parm_len = DoGCKB(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('K','C'):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mGCKC);
         break;
      case  MAKEINT('K','P'):
         parm_len = DoGCKP(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('D','1'):
      case  MAKEINT('D','2'):
      case  MAKEINT('D','3'):
      case  MAKEINT('D','4'):
         parm_len = DoGCDX(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('B','0'):
      case  MAKEINT('B','1'):
      case  MAKEINT('B','2'):
      case  MAKEINT('B','3'):
         parm_len = DoGCBX(p_cmd,p_resp_parm);
         break;
      case  MAKEINT('S','P'):
         parm_len = DoGCSP(p_cmd, p_resp_parm);
         break;
         */
      case  MAKEINT('P','R'):
         parm_len = DoGCPR(p_cmd, p_resp_parm);
         break;
         /*
      case  MAKEINT('S','I'):
         parm_len = DoGCSI(p_cmd, p_resp_parm);
         break;
      case  MAKEINT('S','Q'):
         parm_len = DoGCSQ(p_cmd, p_resp_parm);
         break;
      case  MAKEINT('S','R'):
         parm_len = DoGCSR(p_cmd, p_resp_parm);
         break;
      case  MAKEINT('S','S'):
         parm_len = DoGCSS(p_cmd, p_resp_parm);
         break;
      case  MAKEINT('S','V'):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mGCSV);
         break;
      case  MAKEINT('C','F'):
         parm_len = DoGCCF( p_cmd, p_resp_parm, &mGCCF );
         break;
      case  MAKEINT('C','W'):
         parm_len = DoCmd( p_cmd, p_resp_parm, &mGCCW );
         break;
      case  MAKEINT('I','N'):
         parm_len = DoGCIN( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('R','L'):
         parm_len = DoGCRL( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('R','N'):
         parm_len = DoGCRN( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('H','R'):
         parm_len = DoGCHR( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('H','S'):
         parm_len = DoGCHS( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('R','Y'):
         parm_len = DoGCRY( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('P','O'):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mGCPO);
         break;
      case  MAKEINT('P','U'):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mGCPU);
         break;
      case  MAKEINT('T','M'):
         parm_len = DoCmd(p_cmd, p_resp_parm, &mGCTM);
         break;
      case  MAKEINT('R','I'):
         parm_len = DoStatus(p_cmd, p_resp_parm, &mGCRI);
         break;
      case  MAKEINT('S','T'):
         parm_len = DoStatus(p_cmd, p_resp_parm, &mGCST);
         break;
      case  MAKEINT('S','A'):
         parm_len = DoStatus(p_cmd, p_resp_parm, &mGCSA);
         break;
      case  MAKEINT('R','T'):
         parm_len = DoGCRT( p_cmd );
         break;
      case  MAKEINT('R','D'):
         parm_len = DoGCRD( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('R','R'):
         parm_len = DoGCRR( p_resp_parm );
         break;

      case  MAKEINT('C','T'):
         parm_len = DoGCCT( p_cmd );
         break;
      case  MAKEINT('C','D'):
         parm_len = DoGCCD( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('C','R'):
         parm_len = DoGCCR( p_resp_parm );
         break;

      case  MAKEINT('E','S'):
         parm_len = DoGCES( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('E','L'):
         parm_len = DoGCEL( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('E','A'):
         parm_len = DoGCEA( p_cmd, p_resp_parm );
         break;
      case  MAKEINT('E','D'):
         parm_len = DoGCED( p_cmd, p_resp_parm );
         break;

      case  MAKEINT('E','O'):
        parm_len = DoGCEO(p_cmd,p_resp_parm);
        break;
        */
      default:
         if (( p_cmd->opcode.int_op >= MAKEINT('R','a') ) &&
             ( p_cmd->opcode.int_op <= MAKEINT('R','y') ))
         {
            parm_len = DoGCRx( p_cmd, p_resp_parm );
         }
         else
         {
            parm_len = NO_RESPONSE;
            CmdErrorHandler( p_cmd, 0, INVALID_OP );
         }
         break;
   }

   return parm_len;
}


/***********************************************************************/
/* END FUNCTION: GCOpcodes                                             */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: GC_Cmds                                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls function which executes a command if one is          */
/*          available on the command queue.                            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

void GC_Cmds(void)
{
   ExecCmds(&GC_Cmd_Q,GCOpcodes);
}

/***********************************************************************/
/* END FUNCTION: GC_Cmds                                               */
/***********************************************************************/

